﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Web;
using System.Data;

namespace WebSys.UI.Control.ZhengShou
{
    public class ZJ_XZMJBCJControl : MPBasicTemplate
    {
        CustomGridView CustomGridView1;
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        public string userid = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            if (HttpContext.Current.Session["UserID"] == null)
            {
                Antu.Utilities.UtilitiesPage.AlertDialogClear("登录超时，请重新登录！", "window.parent.location.href('../login.aspx');");
            }
            else
            {
                userid = HttpContext.Current.Session["UserID"].ToString();
            }
            base.OnLoad(e);
            IninControl();
            if (!base.Page.IsPostBack)
            {
                BindData();
            }
            CustomGridView1.OnLoadData+=new EventHandler(CustomGridView1_OnLoadData);
            Button btnQuery = (Button)FindControl("btnQuery");
            Button bt_delete = (Button)FindControl("bt_delete");
            btnQuery.Click += new EventHandler(btnQuery_Click);
            bt_delete.Click+=new EventHandler(bt_delete_Click);
        }
        protected void IninControl() {
            CustomGridView1 = (CustomGridView)FindControl("CustomGridView1");
        }
        private void BindData()
        {
            CustomGridView1.RowCreated+=new GridViewRowEventHandler(CustomGridView1_RowCreated);
            List<EluZSProvider.ADDAREA> addarea = _EluZSDataProvider.GetAddareaList(GetStrWhere());
            CustomGridView1.DataSource = addarea;
            CustomGridView1.PageSize = 10;
            CustomGridView1.RecordCount = addarea.Count;
            CustomGridView1.HideColName = "ID";
            CustomGridView1.DataKeyNames = new string[] { "ID" };
            CustomGridView1.DataBind();
        }
        protected string GetStrWhere() {
            string strwhere = string.Empty;
            TextBox txt_person = (TextBox)FindControl("txt_person");
            TextBox txt_money = (TextBox)FindControl("txt_money");
            TextBox txt_Identfid = (TextBox)FindControl("txt_Identfid");
            TextBox txt_number = (TextBox)FindControl("txt_number");
            MPCalendar cd_JkStart = (MPCalendar)FindControl("cd_JkStart");
            MPCalendar cd_JkEnd = (MPCalendar)FindControl("cd_JkEnd");
            MPCalendar cd_DfStart = (MPCalendar)FindControl("cd_DfStart");
            MPCalendar cd_DfEnd = (MPCalendar)FindControl("cd_DfEnd");
            DropDownList ddl兑付情况 = (DropDownList)FindControl("ddl兑付情况");
            if (!string.IsNullOrEmpty(txt_person.Text)) { strwhere += " and 缴纳人 like '%" + txt_person.Text + "%'"; }
            if (!string.IsNullOrEmpty(txt_money.Text)) { strwhere += " and 缴纳金额 like '%" + txt_money.Text + "%'"; }
            if (!string.IsNullOrEmpty(txt_Identfid.Text)) { strwhere += " and 身份证号 like '%" + txt_Identfid.Text + "%'"; }
            if (!string.IsNullOrEmpty(txt_number.Text)) { strwhere += " and 单据编号 like '%" + txt_number.Text + "%'"; }

            if (!string.IsNullOrEmpty(cd_JkStart.Text)) { strwhere += " and 缴纳时间 >= to_date('" + cd_JkStart.Text + "','yyyy-MM-dd')"; }
            if (!string.IsNullOrEmpty(cd_JkEnd.Text)) { strwhere += " and 缴纳时间 < to_date('" + cd_JkEnd.Text + "','yyyy-MM-dd')"; }
            if (!string.IsNullOrEmpty(cd_DfStart.Text)) { strwhere += " and 兑付时间 >= to_date('" + cd_DfStart.Text + "','yyyy-MM-dd')"; ; }
            if (!string.IsNullOrEmpty(cd_DfEnd.Text)) { strwhere += " and 兑付时间 < to_date('" + cd_DfEnd.Text + "','yyyy-MM-dd')"; }
            if (!string.IsNullOrEmpty(ddl兑付情况.SelectedValue)) { strwhere += " and 兑付情况='" + ddl兑付情况.SelectedValue + "'"; }
            strwhere += " order by 兑付时间 desc ";
            return strwhere;
        }
        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }

        protected void CustomGridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.DataRow:
                    {
                        EluZSProvider.ADDAREA rowview = (EluZSProvider.ADDAREA)e.Row.DataItem;
                        if (e.Row.DataItem == null)
                        {
                            break;
                        }
                        TableCellCollection cells = e.Row.Cells;
                        TableCell cell = new TableCell();
                        Label lbjnje = (Label)FindControl("lbjnje");
                        string strId = rowview.单据编号;
                        lbjnje.Text = "";
                        if (string.IsNullOrEmpty(strId))
                        {
                            e.Row.Cells[10].Text = "";
                            CheckBox cbxTemp = e.Row.Cells[2].Controls[0] as CheckBox;
                            if (cbxTemp != null)
                            {
                                cbxTemp.Visible = false;
                                e.Row.Cells[2].Text = "合计";
                                e.Row.Visible = false;
                                string temp = rowview.缴纳金额;
                                if (string.IsNullOrEmpty(temp)) { temp = "0"; }
                                lbjnje.Text = "合计缴纳金额：" + string.Format("{0:N}", Convert.ToDouble(temp)) + "元";
                            }
                        }
                        break;
                    }
            }
        }
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void bt_delete_Click(object sender, EventArgs e)
        {
            DataKey[] sd = CustomGridView1.SelectedDataKeys;
            if (sd.Length > 0)
            {
                foreach (DataKey key in sd)
                {
                    bool del = _EluZSDataProvider.DeleteXmByID("ZS_ADDAREA", "ID", key.Value.ToString());
                }
            }
            HttpContext.Current.Response.Redirect("ZJ_XZMJBCJ.aspx");
        }
    }
}


